package com.yanyilu.qiubite.util;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;

public class QRCodeGeneratorUtil{
//    private static final String QR_CODE_IMAGE_PATH = "/Users/gisboy/Desktop/";
//    private static final String QR_CODE_IMAGE_PATH = "E:/apache-tomcat-8.5.11/webapps/qiubite/";
//    private static final String QR_CODE_IMAGE_PATH = "C:/apache-tomcat-8.5.11/webapps/qiubite/imgs/";
    private static final String QR_CODE_IMAGE_PATH = "/www/admin/qiubite-api.makabaka.ltd_80/wwwroot/upload/";
//    private static final String FILE_HEAD = "http://www.ifuture.site:8089/qiubite/imgs/";


    public static String generateQRCodeImage(String text, int width, int height, String fileName) throws WriterException, IOException, WriterException, IOException {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();

        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);

        Path path = FileSystems.getDefault().getPath(QR_CODE_IMAGE_PATH+fileName);

        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);

        return QR_CODE_IMAGE_PATH+fileName;
    }


}
